<template>
    <div id="redirectMain">
        <div id="preInfoStatus">{{preInfo}}</div>
        <div id="returnInfoStatus">{{returnInfo}}</div>
        <div>当前是Redirect页面</div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                code : undefined,
                accessToken: undefined,
                refreshToken: undefined,
                preInfo: "init",
                returnInfo: "",
            }
        },
        created(){
            let nextProcedure = this.$route.query.state;
            let code = this.$route.query.code;
            let accessToken = this.$route.query.access_token;
            let refreshToken = this.$route.query.refresh_token;
            switch (nextProcedure) {
                case "refreshToken":{
                    let localRefreshToken = (this.$cookies.get("Cus-Auth2-RefreshToken") === null) ? "" : this.$cookies.get("Cus-Auth2-RefreshToken");
                    this.CommonFunction.oauth2RefreshTokenTestClient(this, localRefreshToken);
                    break;
                }
                case "login":{
                    this.CommonFunction.oauth2LoginTestClient(this);
                    break;
                }
                case "getToken":{   //有code, 需要获取token(第二步)
                    this.preInfo = "开始获取token";
                    this.CommonFunction.oauth2GetTokenTestClient(this, code);
                    break;
                }
                case "gotoResource":{   //有token, 定向至资源页(第三步)
                    this.$cookies.set("Cus-Auth2-AccessToken",accessToken,"9h","/",'127.0.0.1');
                    this.$cookies.set("Cus-Auth2-RefreshToken",refreshToken,"9h","/",'127.0.0.1');
                    window.location.href = (this.$cookies.get("Resource-Uri") === null) ? "/index" : this.$cookies.get("Resource-Uri");
                    break;
                }
                default:{    //需要获取code(第一步)
                    let userChoose = this.$route.query.action;
                    if (userChoose === "accept"){
                        this.CommonFunction.oauth2GetCodeTestClient(this);
                    }else if (userChoose === "reject"){
                        // TODO: 拒绝授权页面
                        this.preInfo = "用户拒绝授权";
                    }else{
                        this.preInfo = "服务器内部错误";
                    }
                    break;
                }
            }
        },
        methods: {

        },
    }
</script>

<style scoped>

</style>